<?php
namespace Home\Controller;
use Think\Controller;

class NewsController extends  BaseController
{
	public function index(){
		
		//分页
		$page = intval($GLOBALS['request']['page']);
		if($page==0)
			$page = 1;
		
		$root = get_baseroot();
		
		$article_cates = $GLOBALS['db']->getAll("SELECT * FROM ".DB_PREFIX."article_cate where is_effect=1 AND is_delete= 0 AND type_id=0 ORDER BY sort DESC,id DESC ");
		$root['article_cates'] = $article_cates;
		
		$cate_id =intval($GLOBALS['request']['id']);
		if($cate_id == 0){
			$cate_id = (int)$article_cates[0]['id'];
		}
		if($cate_id >0){
			$extW = " and cate_id = ".$cate_id."  ";
		}
		
		
		//分页
		$limit = (($page-1)*app_conf("PAGE_SIZE")).",".app_conf("PAGE_SIZE");
		
		$sql = "select * from ".DB_PREFIX."article where is_effect = 1 and is_delete = 0 ".$extW." order by sort DESC,id DESC ";
		$sql.=" limit ".$limit;
		
		$sql_count = "select count(*) from ".DB_PREFIX."article where is_effect = 1 and is_delete = 0 ".$extW;
		

		$count = $GLOBALS['db']->getOne($sql_count);
		$list = $GLOBALS['db']->getAll($sql);
		foreach($list as $k=>$v){
			if ($v['icon'] != '')
				$v['icon'] = get_abs_wap_url_root(get_abs_img_root($v['icon']));
			$list[$k] = $v;
		}
	
						
		$root['page'] = array("page"=>$page,"page_total"=>ceil($count/app_conf("PAGE_SIZE")),"page_size"=>app_conf("PAGE_SIZE"));	
		
		$root['response_code'] = 1;
		$root['cate_id'] = $cate_id;
		$root['list'] = $list;
		$root['program_title'] = "文章列表";
		output($root);		
	}
}
?>
